package tests.jdl.databaseObjects;

import jdl.databaseObjects.DbField;
import jdl.databaseObjects.DbType;
import jdl.databaseObjects.ObjectAlreadyExistsException;
import jdl.databaseObjects.Table;
import jdl.databaseObjects.sqlite.datatypes.IntDbType;
import junit.framework.Assert;

import org.junit.Test;
import org.mockito.Mockito;

public class DbField_Test {
	@Test
	public void getName() {
		DbField field = new DbField("hi", new IntDbType());
		Assert.assertEquals("hi", field.getName());
	}

	@Test
	public void getFieldCollection() throws ObjectAlreadyExistsException {
		Table table = new Table("hello");
		DbField field = new DbField("id", new IntDbType());
		table.addField(field);
		Assert.assertEquals(table.getFieldCollection(),
				field.getFieldCollection());
	}

	@Test
	public void changeDbType() {
		DbType type = Mockito.mock(DbType.class);
		DbField field = new DbField("id", type);
		DbType otherType = Mockito.mock(DbType.class);
		field.changeDbType(otherType);
		Assert.assertEquals(otherType, field.getDbType());
	}

	@Test(expected = IllegalArgumentException.class)
	public void changeDbType_dbTypeIsNull() {
		DbType type = Mockito.mock(DbType.class);
		DbField field = new DbField("hello", type);
		field.changeDbType(null);
	}
}
